import pymysql

conn = None
cursor = None
try:
    conn = pymysql.connect(host='192.168.174.132', port=3306, user='root', password='iTest_2022_mysql',
                           database='test_db', charset='utf8')
    cursor = conn.cursor()
    insert_sql = "INSERT INTO user_profile VALUES(1,2138,'male',21,'北京大学','BeiJing')\
         ,(2,3214,'male',null,'复旦大学','Shanghai')\
         ,(3,6543,'female',20,'北京大学','BeiJing')\
         ,(4,2315,'female',23,'浙江大学','ZheJiang')\
         ,(5,5432,'male',25,'山东大学','Shandong');"
    cursor.execute(insert_sql)
    conn.commit()
except Exception as err:
    print('错误信息:', err)
    conn.rollback()
    pass
finally:
    cursor.close()
    conn.close()

